<%-- 
    Document   : searchAjax
    Created on : Jan 6, 2014, 9:17:21 PM
    Author     : THICH HOA DONG TIEN
--%>

<%@page import="bc.entity.Nganh"%>
<%@page import="businesscard.DAO.NganhDAO"%>
<%@page import="bc.entity.Thanhpho"%>
<%@page import="businesscard.DAO.ThanhphoDAO"%>
<%@page import="bc.entity.Quanhuyen"%>
<%@page import="businesscard.DAO.QuanhuyenDAO"%>
<%@page import="bc.entity.Bophan"%>
<%@page import="businesscard.DAO.BophanDAO"%>
<%@page import="bc.entity.Capbac"%>
<%@page import="businesscard.DAO.CapbacDAO"%>
<%@page import="bc.entity.Congty"%>
<%@page import="businesscard.DAO.CongtyDAO"%>
<%@page import="bc.entity.Lienhe"%>
<%@page import="java.util.List"%>
<%@page import="businesscard.DAO.LienheDAO"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <% String name = request.getParameter("search");
            LienheDAO lhdao1 = new LienheDAO();
            List<Lienhe> lienhelist = lhdao1.getLienheLikeName(name);
            if (!lienhelist.isEmpty()) {

                for (int i = 0; i < lienhelist.size(); i++) {
                    String tenlienhe = lienhelist.get(i).getTen();
                    String tennganh = lienhelist.get(i).getNganh().getNganh();
                    int idlienhe = lienhelist.get(i).getIdLienhe();
        %>
        <div class="show" align="left">
            <span class="name" id="searchall"><a href="CTLienhe.jsp?malienhe=<%=idlienhe%>"><%=tenlienhe%></a></span>&nbsp;<br/><%=tennganh%><br/>
        </div>
        <%
            }
        } else {

            CongtyDAO ctdao1 = new CongtyDAO();
            List<Congty> ctList1 = ctdao1.getCongtyLikesName(name);
            if (!ctList1.isEmpty()) {
                for (int i = 0; i < ctList1.size(); i++) {
                    String tencongty = ctList1.get(i).getCongty();
                    int idcongty = ctList1.get(i).getIdCongty();
                    String nganh = ctList1.get(i).getNganh().getNganh();
        %>
        <div class="show" align="left">
            <span class="name"><a href="LHbyCongty.jsp?macongty=<%=idcongty%>"><%=tencongty%></a></span>&nbsp;<br/><%=nganh%><br/>
        </div>
        <%
            }
        } else {
            CapbacDAO cbdao1 = new CapbacDAO();
            List<Capbac> cbList1 = cbdao1.getCapbacLikeName(name);
            if (!cbList1.isEmpty()) {
                for (int i = 0; i < cbList1.size(); i++) {
                    String tencapbac = cbList1.get(i).getCapbac();
                    int idcapbac = cbList1.get(i).getIdCapbac();
        %>
        <div class="show" align="left">
            <span class="name"><a href="LHbyCapbac.jsp?macapbac=<%=idcapbac%>"<%=tencapbac%></span>
        </div>
        <%
            }

        } else {
            BophanDAO bpdao1 = new BophanDAO();
            List<Bophan> bpList1 = bpdao1.getBophanLikeName(name);
            if (!bpList1.isEmpty()) {
                for (int i = 0; i < bpList1.size(); i++) {
                    String tenbophan = bpList1.get(i).getBophan();
                    int idbophan = bpList1.get(i).getIdBophan();
        %>
        <div class="show" align="left">
            <span class="name"><%=tenbophan%></span>
        </div>
        <%
            }

        } else {
            QuanhuyenDAO qhdao1 = new QuanhuyenDAO();
            List<Quanhuyen> qhList1 = qhdao1.getQuanhuyenLikeName(name);
            if (!qhList1.isEmpty()) {
                for (int i = 0; i < qhList1.size(); i++) {
                    String tenquanhuyen = qhList1.get(i).getQuanhuyen();
                    int idquanhuyen = qhList1.get(i).getIdQuanhuyen();
        %>
        <div class="show" align="left">
            <span class="name"><a href="LHbyQuan.jsp?maquan=<%=idquanhuyen%>"><%=tenquanhuyen%></a></span>
        </div>
        <%
            }

        } else {
            ThanhphoDAO tpdao1 = new ThanhphoDAO();
            List<Thanhpho> tpList1 = tpdao1.getThanhphoLikeName(name);
            if (!tpList1.isEmpty()) {
                for (int i = 0; i < tpList1.size(); i++) {
                    String tenthanhpho = tpList1.get(i).getThanhpho();
                    int idthanhpho = tpList1.get(i).getIdThanhpho();

        %>
        <div class="show" align="left">
            <span class="name"><a href="LHbyThanhpho.jsp?mathanhpho=<%=idthanhpho%>"><%=tenthanhpho%></a></span>
        </div>
        <%

            }

        } else {
            NganhDAO nganhdao = new NganhDAO();
            List<Nganh> nganh = nganhdao.getNganhlikeName(name);
            if (!nganh.isEmpty()) {
                for (int i = 0; i < nganh.size(); i++) {
                    String tennganh = nganh.get(i).getNganh();
                    int idnganh = nganh.get(i).getIdNganh();
        %>
        <div class="show" align="left">
            <span class="name"><a href="LHbyNganh.jsp?manganh=<%=idnganh%>"><%=tennganh%></a></span>
        </div>
        <%
            }

        } else {
        %>
        <div class="show" align="left">
            <span class="name">Không có kết quả tìm kiếm nào</span>
        </div>
        <%
                                    }

                                }
                            }
                        }

                    }

                }

            }

        %>
    </body>
</html>
